from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-13 14:10:48.451579
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 13, Apr, 2021
Time: 14:10:53
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5006
Nobs: 260.000 HQIC: -48.2377
Log likelihood: 3104.99 FPE: 6.84873e-22
AIC: -48.7332 Det(Omega_mle): 4.87637e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.448875 0.124273 3.612 0.000
L1.Burgenland 0.069693 0.061715 1.129 0.259
L1.Kärnten -0.222729 0.053634 -4.153 0.000
L1.Niederösterreich 0.059733 0.133407 0.448 0.654
L1.Oberösterreich 0.220086 0.126195 1.744 0.081
L1.Salzburg 0.271453 0.069729 3.893 0.000
L1.Steiermark 0.130237 0.089005 1.463 0.143
L1.Tirol 0.122308 0.061133 2.001 0.045
L1.Vorarlberg -0.030257 0.056397 -0.536 0.592
L1.Wien -0.057094 0.115009 -0.496 0.620
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.488782 0.146565 3.335 0.001
L1.Burgenland -0.004242 0.072786 -0.058 0.954
L1.Kärnten 0.329112 0.063255 5.203 0.000
L1.Niederösterreich 0.075591 0.157337 0.480 0.631
L1.Oberösterreich -0.061361 0.148832 -0.412 0.680
L1.Salzburg 0.221702 0.082237 2.696 0.007
L1.Steiermark 0.109599 0.104971 1.044 0.296
L1.Tirol 0.143040 0.072099 1.984 0.047
L1.Vorarlberg 0.154816 0.066513 2.328 0.020
L1.Wien -0.444349 0.135639 -3.276 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.289984 0.062698 4.625 0.000
L1.Burgenland 0.090688 0.031137 2.913 0.004
L1.Kärnten -0.018224 0.027060 -0.673 0.501
L1.Niederösterreich 0.054610 0.067307 0.811 0.417
L1.Oberösterreich 0.277394 0.063668 4.357 0.000
L1.Salzburg 0.024719 0.035180 0.703 0.482
L1.Steiermark 0.010820 0.044905 0.241 0.810
L1.Tirol 0.073108 0.030843 2.370 0.018
L1.Vorarlberg 0.081734 0.028453 2.873 0.004
L1.Wien 0.119613 0.058024 2.061 0.039
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218804 0.061388 3.564 0.000
L1.Burgenland 0.021941 0.030486 0.720 0.472
L1.Kärnten 0.009285 0.026494 0.350 0.726
L1.Niederösterreich 0.052261 0.065900 0.793 0.428
L1.Oberösterreich 0.400410 0.062337 6.423 0.000
L1.Salzburg 0.082293 0.034444 2.389 0.017
L1.Steiermark 0.129498 0.043967 2.945 0.003
L1.Tirol 0.050011 0.030198 1.656 0.098
L1.Vorarlberg 0.084836 0.027859 3.045 0.002
L1.Wien -0.049156 0.056812 -0.865 0.387
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.504420 0.119873 4.208 0.000
L1.Burgenland 0.089419 0.059530 1.502 0.133
L1.Kärnten 0.011717 0.051735 0.226 0.821
L1.Niederösterreich 0.001985 0.128684 0.015 0.988
L1.Oberösterreich 0.130421 0.121727 1.071 0.284
L1.Salzburg 0.058484 0.067260 0.870 0.385
L1.Steiermark 0.067575 0.085854 0.787 0.431
L1.Tirol 0.213543 0.058969 3.621 0.000
L1.Vorarlberg 0.031847 0.054400 0.585 0.558
L1.Wien -0.101484 0.110937 -0.915 0.360
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188112 0.094782 1.985 0.047
L1.Burgenland -0.012284 0.047070 -0.261 0.794
L1.Kärnten -0.007880 0.040906 -0.193 0.847
L1.Niederösterreich -0.004557 0.101748 -0.045 0.964
L1.Oberösterreich 0.398584 0.096248 4.141 0.000
L1.Salzburg 0.016624 0.053182 0.313 0.755
L1.Steiermark -0.018665 0.067884 -0.275 0.783
L1.Tirol 0.159058 0.046626 3.411 0.001
L1.Vorarlberg 0.053005 0.043013 1.232 0.218
L1.Wien 0.233021 0.087716 2.657 0.008
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240147 0.115390 2.081 0.037
L1.Burgenland 0.019253 0.057304 0.336 0.737
L1.Kärnten -0.068750 0.049800 -1.381 0.167
L1.Niederösterreich -0.069824 0.123871 -0.564 0.573
L1.Oberösterreich 0.019583 0.117174 0.167 0.867
L1.Salzburg 0.082491 0.064745 1.274 0.203
L1.Steiermark 0.335404 0.082643 4.058 0.000
L1.Tirol 0.461879 0.056763 8.137 0.000
L1.Vorarlberg 0.147692 0.052366 2.820 0.005
L1.Wien -0.163537 0.106788 -1.531 0.126
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181179 0.137595 1.317 0.188
L1.Burgenland 0.040848 0.068331 0.598 0.550
L1.Kärnten -0.075220 0.059384 -1.267 0.205
L1.Niederösterreich 0.127710 0.147708 0.865 0.387
L1.Oberösterreich 0.015354 0.139723 0.110 0.912
L1.Salzburg 0.200864 0.077204 2.602 0.009
L1.Steiermark 0.118144 0.098547 1.199 0.231
L1.Tirol 0.057115 0.067687 0.844 0.399
L1.Vorarlberg 0.106647 0.062443 1.708 0.088
L1.Wien 0.233901 0.127338 1.837 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.568940 0.074299 7.657 0.000
L1.Burgenland -0.033238 0.036898 -0.901 0.368
L1.Kärnten -0.023223 0.032067 -0.724 0.469
L1.Niederösterreich 0.045837 0.079760 0.575 0.566
L1.Oberösterreich 0.315168 0.075449 4.177 0.000
L1.Salzburg 0.021659 0.041689 0.520 0.603
L1.Steiermark -0.034330 0.053214 -0.645 0.519
L1.Tirol 0.087039 0.036550 2.381 0.017
L1.Vorarlberg 0.108249 0.033718 3.210 0.001
L1.Wien -0.049305 0.068761 -0.717 0.473
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.145875 0.074820 0.165520 0.221822 0.079929 0.083742 0.008620 0.153267
Kärnten 0.145875 1.000000 0.036103 0.202523 0.178091 -0.061520 0.163738 0.026689 0.302855
Niederösterreich 0.074820 0.036103 1.000000 0.237589 0.075408 0.323839 0.141667 0.026162 0.293275
Oberösterreich 0.165520 0.202523 0.237589 1.000000 0.301033 0.269098 0.089318 0.061545 0.134547
Salzburg 0.221822 0.178091 0.075408 0.301033 1.000000 0.155117 0.053011 0.089186 0.006079
Steiermark 0.079929 -0.061520 0.323839 0.269098 0.155117 1.000000 0.104260 0.095805 -0.106491
Tirol 0.083742 0.163738 0.141667 0.089318 0.053011 0.104260 1.000000 0.162067 0.147106
Vorarlberg 0.008620 0.026689 0.026162 0.061545 0.089186 0.095805 0.162067 1.000000 -0.005638
Wien 0.153267 0.302855 0.293275 0.134547 0.006079 -0.106491 0.147106 -0.005638 1.000000